899B - Months and Years - CodeForces Solution


implementation *1200

Please click on ads to support us..

Python Code:

input()
print('Yes' if input() in ('31 28 31 30 31 30 31 31 30 31 30 31 '*3+'31 29 31 30 31 30 31 31 30 31 30 31 ')*2 else 'No')

C++ Code:

#include<bits/stdc++.h>
#define int long long int
using namespace std;
int mod=1e9+7;
signed main()
{
int t,go=0,co=0,e,ro=0;
cin>>t;
int a[t];
for(int i=0;i<t;i++){cin>>a[i];}

for(int i=0;i<t;i++){
    if(a[i]==30 && i!=t-1 ){
        if(a[i+1]==30){go++;
        }
    }
      if((a[i]==29 || a[i]==28) && i!=t-1 ){
        if(a[i+1]!=31)go++;
    }
  
    if(a[i]==28 || a[i]==29){
        ro++;
        if(co==0){
          co++;
          e=i;}
          else{
            if(i-e !=12)go++;
          }

    }
    if(a[i]==29 && i+12<=t-1){
        if(a[i+12]==29 || a[i+12]==30||a[i+12]==31 )go++;

    }
}
if(ro==0 && t>11)go++;
co=0;
for(int i=0;i<t;i++){
    if(a[i]==31 && i!=t-1){
        if(a[i+1]==31){
             if(co==0){
                e=i;
                co++;
             }
             else{
                if(i-e !=5 &&  i-e!=7)go++;
                else e=i;
             }
        }
    }
}
if(go==0)cout<<"YES";
else cout<<"NO";
 return 0;
}


Comments

Submit
0 Comments
More Questions

99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple
1675B - Make It Increasing
588A - Duff and Meat
1541B - Pleasant Pairs
1626B - Minor Reduction
1680A - Minimums and Maximums
1713A - Traveling Salesman Problem
1713B - Optimal Reduction
1710A - Color the Picture
1686B - Odd Subarrays
251A - Points on Line
427C - Checkposts
1159A - A pile of stones
508A - Pasha and Pixels
912A - Tricky Alchemy
1249A - Yet Another Dividing into Teams
1713C - Build Permutation
1699A - The Third Three Number Problem
1617B - GCD Problem
841A - Generous Kefa
1690B - Array Decrements
1692C - Where's the Bishop
104A - Blackjack
1438A - Specific Tastes of Andre
1711C - Color the Picture
1194C - From S To T
110B - Lucky String